﻿
using System;
using System.Collections.Generic;
using System.Net.Http.Formatting;
using System.Web.Http;
using System.Web.Http.Controllers;

namespace HpaApi.WebApi
{
    /// <summary>
    /// 
    /// </summary>
    [AttributeUsage(AttributeTargets.Parameter)]
    public class ConcreteAttribute : ParameterBindingAttribute
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="implement"></param>
        public ConcreteAttribute(Type implement)
        {
            ImplementType = implement;
        }

        /// <summary>
        /// 
        /// </summary>
        public Type ImplementType { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
        {
            HttpConfiguration configuration = parameter.Configuration;
            IEnumerable<MediaTypeFormatter> formatters = configuration.Formatters;

            return new ConcreteParamterBinding(parameter, formatters, configuration.Services.GetBodyModelValidator(), ImplementType);
        }

    }
}